/**
 * by samsun
 */
//模型文件版本数据
var versioninfoStore = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({	//proxy从哪里获取数据
		url : 'showDomainModelVersionInfo.action?method=showDomainModelVersionInfo',
		method : 'post'
	}),
	reader : new Ext.data.JsonReader({	//reader如何解析数据
		root : 'versionInfo',
		totalProperty : 'totalVersionInfoSize',
		id : 'versionId'
	}, [ {
		name : 'groupId'
	}, {
		name : 'time'
	},{
		name : 'author'
	}, {
		name : 'versionId'
	}
	])
});
//版本表格列模型
var versioninfosm=new Ext.grid.CheckboxSelectionModel ({singleSelect : false});
var versioninfoColumnModel=new Ext.grid.ColumnModel(
		[versioninfosm,
		 new Ext.grid.RowNumberer(),
		 {
			header : '版本号',
			width : 100,
			dataIndex : 'versionId',
			sortable : true,
			align : 'center'
		 },   {
			 header : '修改日期',
			 width : 200,
			 dataIndex : 'time',
			 sortable : true,
             align : 'center'
		 },{
			 header : '作者',
			 width : 100,
			 dataIndex : 'author',
			 sortable : true,
			 align : 'center'
         },{
			 header : '模型种类',
			 width : 100,
			 dataIndex : 'groupId',
			 sortable : true,
			 align : 'center'
         }]
          );
//模型版本信息列表
          
var versioninfoList=new Ext.grid.EditorGridPanel({
	title: "版本历史",
	region:'center',
	ds : versioninfoStore,	//绑定store
	enableColumnResize : true,
	border : true,
	//clicksToEdit:1,
	enableColumnMove : true,
	enableHdMenu : false,
	stripeRows: true, //显示斑马线
	loadMask: true,
	autoHeight:true,
	bodyStyle:'width:100%',
    autoWidth:true,
    editable:true,
    sm : versioninfosm,
    bbar: new Ext.PagingToolbar({//下面的分页条
        pageSize: 15,
        store: versioninfoStore,
        displayInfo: true,
        displayMsg: '当前显示第 {0} 条到 {1} 条记录，一共 {2} 条',
        emptyMsg: "没有记录",
        lastText:"尾页",   
        nextText :"下一页",   
        prevText :"上一页",   
        firstText :"首页",   
        refreshText:"刷新页面"        
    }),
	cm : versioninfoColumnModel,
	store : versioninfoStore
});

var versioninfoTabPanel = new Ext.TabPanel({
	border : true,
	region:'south',
	autoScroll:true,
	height:200,
	items:[ versioninfoList,
	{
	title: "业务对象具体信息",
	region:'center',
	height:200,
	collapsible : true,
	border:false,
	contentEl:'domainDetail'
	}]
	,
	activeItem: 1
	});


var domain = new Ext.Panel({
	id : 'domain-panel',
	title : '业务对象视图',
	layout : 'border',
	//closable:true,
	defaults : {
	
		bodyStyle : 'padding:15px'
	},
	items : [
	         versioninfoTabPanel,
	         {
	    region : 'center',
		autoScroll:true,
		border : false,
		contentEl : 'domainCanvas'
	} ]
});

function showModelContent(cid,text) {
	
	versioninfoStore.load({
    	params:{
    		cid:cid
    	},
    	callback: function(r, options, success) { 
    		if (success == false) { 
    		alert("加载domain-version数据失败，无对应数据或者系统出现异常！"); 
    		}
    		else{
    		//alert("加载domain-version数据成功！");	
    		}
    	}
    });
	    Ext.getDom('domainDetail').innerHTML = "";
		var attributeStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : 'showDomainModelAttribute.action?method=showDomainModelAttribute',
			method : 'post'
			
		}),
		reader : new Ext.data.JsonReader({
			root : "Domainmodelattr",
			totalProperty : "totalAttribute",
			id:"id"
	    }, [ {
			name : 'id'
		}, {
			name : 'enName'
		},{
			name : 'cnName'
		},{
			name : 'description'
		},{
			name : 'cnType'
		}, {
			name : 'enType'
		}, {
			name : 'typeId'
		}, {
			name : 'minValue'
		}, {
			name : 'maxValue'
		}, {
			name : 'readOnly'
		}, {
			name : 'staticstate'
		}, {
			name : 'uni'
		}, {
			name : 'collectionType'
		}, {
			name : 'defaultValue'
		},{
			name : 'domainModelid'
		}])
	});
	
	attributeStore.load({
		params : {
			cid : cid
		},
		callback: function(r, options, success) { 
		if (success == false) {  
		alert("加载数据失败，无对应数据或者系统出现异常！"); 
		}else{ 
			
			var cm=new Ext.grid.ColumnModel([
				         						new Ext.grid.RowNumberer(),
				         						{header:'编号',dataIndex:'id'},
				         						{header:'名称(中文)',dataIndex:'cnName'},
				         						{header:'名称(英文)',dataIndex:'enName'},
				         						{header:'类型名称',dataIndex:'cnType'},
				         						{header:'最小值',dataIndex:'minValue'},
				         						{header:'最大值',dataIndex:'maxValue'},
				         						{header:'操作性',dataIndex:'readOnly'},
				         						{header:'唯一性',dataIndex:'uni'},
				         						{header:'集合类型',dataIndex:'collectionType'},
				         						{header:'缺省值',dataIndex:'defaultValue'},
				         						{header:'备注',dataIndex:'description'}
				         						
				         						
				         					]);
				         				var grid=new Ext.grid.GridPanel({
				         						renderTo:'domainDetail',
				         						 viewConfig: {
				         				            forceFit:true
				         				        },
				         						layout:'fit',
				         						stripeRows: true,
				         						autoHeight:true,
				         						loadMask:true,
				         						store:attributeStore,
				         						cm:cm
				         					});
			var stateStore = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
					url : 'showDomainModelState.action?method=showDomainModelState',
					method : 'post'
				}),
				reader : new Ext.data.JsonReader({
					root : "Domainmodelstate",
					totalProperty : "totalState",
					id:"id"
			    }, [ {
					name : 'id'
				}, {
					name : 'enName'
				},{
					name : 'cnName'
				},{
					name : 'description'
				},{
					name : 'domainModelid'
				}])
			});
			stateStore.load({ 
				params : {
					cid : cid
				},
				callback: function(r, options, success) { 
				if (success == false) {  
				alert("加载数据失败，无对应数据或者系统出现异常！"); 
				}else{ 
					var canvas=document.getElementById('domainCanvas');
					var ctx=canvas.getContext('2d');
					drawDomainModel(300,100,ctx,attributeStore,stateStore,text);

				} 
				} 
				}); 
		} 
		} 
		}); 
	
	
	
}

     